package com.meng.thrift.client.common;

import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Properties;


/**
 * 工具类
 *
 * @author MENG
 * @version 2017/11/20
 * @see
 */
public class Utils
{

    /**
     *
     * 读取propertiesName配置文件
     *
     * @param key 配置文件中的key
     * @param propertiesName 配置文件名称
     * @return
     * @throws IOException
     */
    public static String getPropertiesValByKey(String key,String propertiesName) throws IOException
    {
        InputStream inStream = Utils.class.getClassLoader().getResourceAsStream(propertiesName);

        Properties prop = new Properties();

        try
        {
            prop.load(new InputStreamReader(inStream, "UTF-8"));
        }
        catch (IOException e)
        {
            throw new IOException("加载配置文件路径出错->>"+propertiesName,e);
        }

        String value = prop.getProperty(key);

        return value;
    }

    /**
     *
     * 获取email.properties 配置文件中的值
     *
     * @param key
     * @return val
     * @throws IOException
     */
    public static String getThriftpropsValByKey(String key) throws IOException
    {
        return getPropertiesValByKey(key,"thrift_ip_port.properties");
    }

}
